package alg20250212;

public class Text2 {
    public int numDecodings(String ss) {
        char[] s = ss.toCharArray();
        int n = s.length;
        //1 创建表
        int[] dp = new int[n + 1];
        //2 初始化
        dp[0] = 1;
        if(s[1 - 1] != '0') dp[1] = 1;
        //3 填表
        for (int i = 2; i <= n; i++) {
            if(s[i - 1]  != 0) dp[i] += dp[i - 1];
            int sum = s[i - 2] * 10 + s[i - 1];
            if(sum >= 10 && sum <= 26) dp[i] +=dp[i - 2];
        }
        //4 返回值
        return dp[n];
    }
}
